/**
 * 
 */
package any.restlet.helper;

import java.io.IOException;
import java.util.Map;

import org.apache.commons.lang.Validate;
import org.restlet.resource.Representation;
import org.restlet.resource.Variant;

/**
 * Simple implementation of {@link RepresentationHelper}.
 * 
 * @author keke
 * @reversion $Revision: 80 $
 * @version 0.0.1
 * @since 0.0.1
 */
public class SimpleRepresentationHelper implements RepresentationHelper {

    private Map<String, RepresentationHandler> repHelps;

    public void setHelpers(final Map<String, RepresentationHandler> helps) {
        repHelps = helps;
    }

    public Object toEntity(final String name,
            final Representation representation) throws IOException {
        Validate.notNull(name);
        final RepresentationHandler handler = repHelps.get(name);
        return handler == null ? null : handler.toEntity(representation);
    }

    public Representation toRepresentation(final String name,
            final Object entity, final Variant variant) {
        Validate.notNull(name);
        Validate.notNull(variant);
        final RepresentationHandler handler = repHelps.get(name);
        return handler == null ? null : handler.toRepresentation(entity,
                variant);
    }

}
